<script>
  $(document).ready(function(){
     $("#mod_id").change(function(){
         var mod_id = $(this).val();
         if(mod_id!=""){
    	 $.ajax({
        	   type: "POST",
        	   url:"<?php echo  base_url();?>administrator/get_category",
        	   data: "mod_id="+mod_id,
        	   success: function(msg){
            	   $("#category_id").html("");
            	   $("#category_id").html(msg);
            	   $("#version_form").submit();
        	   }
          });   
         }else{
        	 $("#version_form").submit();
         }
     })     

    $("#category_id").change(function(){
         $("#version_form").submit();
     })
     var version_del = $("#version_del").val();
     if(version_del==1){
          alert('此版本下还有资料，此版本不可以删除');
     }
  })
</script>
		<div id="center-column">
			<div class="top-bar">
				<a href="<?php echo  base_url();?>administrator/version_add" class="button">新增</a>
				<h1>Contents</h1>
				<div class="breadcrumbs"><?php echo anchor('main/index','首页');?> / <?php echo anchor('administrator/version','资料版本管理');?></div>
			</div><br />
		   <div class="select-bar">
		  <?php echo form_open('administrator/version',array('id'=>'version_form'));?> 
		    <label>型号：</label><label><select id="mod_id" name="mod_id">
		                      <option value="">全部型号</option>
		                   <?php foreach($mod as $k=>$val){?>
		                      <option value="<?php echo $val->mod_id;?>" <?php if(isset($mod_id)&&($mod_id==$val->mod_id)){?>selected=true<?php }?>><?php echo $val->name;?></option>
		                   <?php }?>
		                 </select>
		    </label>
		    <label>种类：</label>
		    <label><select id="category_id" name="category_id"><option value="">全部资料种类</option></select></label>
<!--		    <label>-->
<!--		    <input type="text" name="textfield" />-->
<!--		    </label>-->
		    <label>
			<input type="submit" name="Submit" value="搜索" />
			</label>
		  </form>	
		  </div>
			<div class="table">
				
				<input type="hidden" value="<?php echo $version_del;?>" id="version_del" >
				<table class="listing" cellpadding="0" cellspacing="0">
					<tr>
						<th class="first" width="22">ID</th>
						<th>型号</th>
						<th>资料种类</th>
						<th>版本名称</th>
						<th>资料编号</th>
						
						<th>资料库存</th>
						<th>备注</th>						
						<th class="last">操作</th>
					</tr>
			    <?php foreach($version as $k=>$val):?>		
					<tr  <?php foreach($last_version as $key=>$v){if(($v['version_id']==$val->version_id)&&($v['category_id']==$val->category_id)) {?>class="bs"<?php } }?>>
                        <td><?php echo $start;?></td>    
                        <td><?php foreach($mod as $j=>$m){ if($val->mod_id==$m->mod_id){echo $m->name;}}?></td>                    
                        <td style="text-align:left;padding-left:5px;width:400px;"><?php foreach($category as $j=>$m){ if($val->category_id==$m->category_id){echo $m->name;}}?></td>
                        <td><?php echo $val->name;?></td>
                        <td><?php foreach($category as $j=>$m){ if($val->category_id==$m->category_id){echo $m->codes;}}?></td>
                        
                        <td><?php echo $val->inventory;?></td>
                        <td><?php echo $val->des;?></td>
                        <td><?php echo anchor('administrator/version_detail/'.$val->version_id,'查看',array('class'=>'version_detail'));?>&nbsp;&nbsp;|&nbsp;&nbsp;<?php echo anchor('administrator/version_edit/'.$val->version_id,'编辑',array('class'=>'mod_edit'));?>&nbsp;&nbsp;|&nbsp;&nbsp;<?php echo anchor('administrator/version_del/'.$val->version_id,'删除',array('class'=>'mod_edit',"onclick"=>"return confirm('您确定要删除吗？')?true:false;"));?></td>
					</tr>
				<?php $start++;endforeach;?>						
				</table>
				<?php echo $page;?>
			</div>
		</div>
	</div>
	<div id="footer"></div>
</div>
<input type="hidden" id="version_mod_id" value="<?php echo $mod_id;?>"/>
<input type="hidden" id="version_category_id" value="<?php echo $category_id;?>"/>
</body>
</html>
<script>
  $(document).ready(function(){
	  var mod_id = $("#version_mod_id").val();
	  var category_id = $("#version_category_id").val();

		 $.ajax({
		  	   type: "POST",
		  	   url:"<?php echo  base_url();?>administrator/get_category",
		  	   data: "mod_id="+mod_id,
		  	   success: function(msg){
		      	   $("#category_id").html("");
		      	   $("#category_id").html(msg);
			       $("select[name=category_id]").val(category_id);
		  	   }
		    });
  
   })
</script>

